package com.yidu.StockControl.service.impl;

import com.yidu.StockControl.entity.CashInventorys;
import com.yidu.StockControl.mapper.CashInventorysMapper;
import com.yidu.StockControl.service.CashInventorysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
现金库存    现金库存    现金库存
 */
@Service
public class CashInventorysServiceImpl implements CashInventorysService {
    @Autowired
    CashInventorysMapper cashInventorysMapper;


    @Override
    public List<CashInventorys> selectCashInventorys(String cashInventorysTime, String accounName, int page, int limit) {
        System.out.println("查询");
        Map map = new HashMap();
        map.put("strWhere",buildWhere(cashInventorysTime,accounName));
        map.put("page",(page-1)*limit);
        map.put("limit",page*limit);
        return cashInventorysMapper.selectCashInventorys(map);
    }
    public String buildWhere (String cashInventorysTime,String accounName) {
        StringBuffer strWhere = new StringBuffer();

        if (cashInventorysTime!=null && !cashInventorysTime.equals("")){
            strWhere.append(" and cashInventorysTime like '%" + cashInventorysTime +"%'" );
        }
        if (accounName!=null && !accounName.equals("")){
            strWhere.append(" and accounName like '%" + accounName +"%'" );
        }
        return strWhere.toString();
    }

    @Override
    public int insertCashInventorysId(CashInventorys cashInventorys) {
        return cashInventorysMapper.insertCashInventorys(cashInventorys);
    }

    @Override
    public void updateCashInventorys(CashInventorys cashInventorys) {
        cashInventorysMapper.updateCashInventorys(cashInventorys);
    }

    @Override
    public void deleteCashInventorys(String cashInventorysId) {
        cashInventorysMapper.deleteCashInventorys(cashInventorysId);
    }

    @Override
    public int selectCashInventorysCount() {
        return cashInventorysMapper.selectCashInventorysCount();
    }


}
